package com.yic.module.device.dal.mysql.inspectionRecordInfo;

import java.util.*;

import cn.hutool.core.util.StrUtil;
import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yic.framework.mybatis.core.mapper.BaseMapperX;
import com.yic.module.device.dal.dataobject.inspectionRecordInfo.InspectionRecordInfoDO;
import org.apache.ibatis.annotations.Mapper;
import com.yic.module.device.controller.admin.inspectionRecordInfo.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 巡检/点检记录明细 Mapper
 *
 * @author 系统管理员
 */
@Mapper
public interface InspectionRecordInfoMapper extends BaseMapperX<InspectionRecordInfoDO> {

    default PageResult<InspectionRecordInfoDO> selectPage(InspectionRecordInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InspectionRecordInfoDO>()
                .eqIfPresent(InspectionRecordInfoDO::getRecordId, reqVO.getRecordId())
                .eqIfPresent(InspectionRecordInfoDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(InspectionRecordInfoDO::getDeviceId, reqVO.getDeviceId())
                .eqIfPresent(InspectionRecordInfoDO::getJobId, reqVO.getJobId())
                .eqIfPresent(InspectionRecordInfoDO::getEntryId, reqVO.getEntryId())
                .eqIfPresent(InspectionRecordInfoDO::getStatus, reqVO.getStatus())
                .eqIfPresent(InspectionRecordInfoDO::getContent, reqVO.getContent())
                .eqIfPresent(InspectionRecordInfoDO::getImages, reqVO.getImages())
                .betweenIfPresent(InspectionRecordInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InspectionRecordInfoDO::getId));
    }

    default List<InspectionRecordInfoDO> selectList(InspectionRecordInfoExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<InspectionRecordInfoDO>()
                .eqIfPresent(InspectionRecordInfoDO::getRecordId, reqVO.getRecordId())
                .eqIfPresent(InspectionRecordInfoDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(InspectionRecordInfoDO::getDeviceId, reqVO.getDeviceId())
                .eqIfPresent(InspectionRecordInfoDO::getJobId, reqVO.getJobId())
                .eqIfPresent(InspectionRecordInfoDO::getEntryId, reqVO.getEntryId())
                .eqIfPresent(InspectionRecordInfoDO::getStatus, reqVO.getStatus())
                .eqIfPresent(InspectionRecordInfoDO::getContent, reqVO.getContent())
                .eqIfPresent(InspectionRecordInfoDO::getImages, reqVO.getImages())
                .betweenIfPresent(InspectionRecordInfoDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(InspectionRecordInfoDO::getId));
    }

    default List<InspectionRecordInfoDO> selectAppList(InspectionRecordInfoExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<InspectionRecordInfoDO>()
                .eqIfPresent(InspectionRecordInfoDO::getRecordId, reqVO.getRecordId())
                .eqIfPresent(InspectionRecordInfoDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(InspectionRecordInfoDO::getDeviceId, reqVO.getDeviceId())
                .eqIfPresent(InspectionRecordInfoDO::getJobId, reqVO.getJobId())
                .eqIfPresent(InspectionRecordInfoDO::getEntryId, reqVO.getEntryId())
                .eqIfPresent(InspectionRecordInfoDO::getStatus, reqVO.getStatus())
                .eqIfPresent(InspectionRecordInfoDO::getContent, reqVO.getContent())
                .eqIfPresent(InspectionRecordInfoDO::getImages, reqVO.getImages())
                .betweenIfPresent(InspectionRecordInfoDO::getCreateTime, reqVO.getCreateTime())
                .inSql(InspectionRecordInfoDO::getEntryId,
                        "select id from device_inspection_plan_entry where deleted = 0 and status = 0 " +
                                "union all select id from device_maintenance_plan_entry where deleted = 0 and status = 0")
                .orderByDesc(InspectionRecordInfoDO::getId));
    }

    default PageResult<InspectionRecordInfoDO> selectPcPage(InspectionRecordInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<InspectionRecordInfoDO>()
                .eqIfPresent(InspectionRecordInfoDO::getRecordId, reqVO.getRecordId())
                .eqIfPresent(InspectionRecordInfoDO::getJobId, reqVO.getJobId())
                .eqIfPresent(InspectionRecordInfoDO::getEntryId, reqVO.getEntryId())
                .eqIfPresent(InspectionRecordInfoDO::getStatus, reqVO.getStatus())
                .likeIfPresent(InspectionRecordInfoDO::getContent, reqVO.getContent())
                .eqIfPresent(InspectionRecordInfoDO::getImages, reqVO.getImages())
                .betweenIfPresent(InspectionRecordInfoDO::getCreateTime, reqVO.getCreateTime())
                .inSql(StrUtil.isNotBlank(reqVO.getPlanName()), InspectionRecordInfoDO::getPlanId, String.join(",", reqVO.getPlanIdList()))
                .inSql(StrUtil.isNotBlank(reqVO.getName()) || StrUtil.isNotBlank(reqVO.getCode()), InspectionRecordInfoDO::getDeviceId, String.join(",", reqVO.getDeviceIdList()))
                .orderByDesc(InspectionRecordInfoDO::getId));
    }

    int updateStatus(@Param("status") Integer status,@Param("id") Long id);
}
